package cn.com.dcsgo.ioc.factory;

import org.springframework.beans.factory.FactoryBean;

/**
 * JavaBeanFactory
 * 要通过spring的FactoryBean来实例化bean，需要将自己的工厂类实现FactoryBean接口
 * 泛型指定返回工厂方法的bean类型
 *
 * @author Dcsgo
 * @since 2025/2/4 10:56
 */

public class JavaBeanFactory implements FactoryBean<JavaBean> {
    private String beanName;

    @Override
    public JavaBean getObject() throws Exception {
        //工厂生成bean的逻辑
        JavaBean javaBean = new JavaBean();
        javaBean.setName(beanName);
        return javaBean;
    }

    @Override
    public Class<?> getObjectType() {
        //工厂生成的bean的类型
        return JavaBean.class;
    }

    /*
 如需多例，重写下面这个方法即可
     * default boolean isSingleton() {
     *         return true;
     *     }
     */

    public String getBeanName() {
        return beanName;
    }

    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }
}
